# -*- encoding=utf8 -*-

__author__ = "code哥"
import socket
from sanic.blueprints import Blueprint
from sanic.views import HTTPMethodView
from sanic import response
from sanic_openapi import doc

blueprint = Blueprint(__name__, '/api')


class APPServiceHost(HTTPMethodView):

    @doc.summary("返回当前主机ip")
    def post(self, request):
        # 获取本机电脑名
        my_name = socket.getfqdn(socket.gethostname())
        # 获取本机ip
        my_addr = socket.gethostbyname(my_name)
        return response.json({'code': 0, 'data': 'http://{addr}:9990/api/reg_wifi_devices'.format(addr=my_addr)})


blueprint.add_route(APPServiceHost.as_view(), '/app_service_host', strict_slashes=True)
